<template>
  <div id="app" :class="{ isMobile: _isMobile() }">
    <v-login />
    <!-- 数据进度 -->
    <el-dialog
      title="数据生成进度"
      :visible.sync="dialogPercent"
      :before-close="closeTypes"
      append-to-body
      width="45%"
      class="eldialog"
    >
      <el-progress class="elprogress" :percentage="percent"></el-progress>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="closeTypes">后台处理</el-button>
      </span>
    </el-dialog>
    <router-view v-if="isReload"></router-view>
  </div>
</template>

<script>
require("@/utils/rem.js");
let types = null;
import axios from "axios";
import VLogin from "@/components/v-login";
import { mapState } from "vuex";
export default {
  provide() {
    return {
      reload: this.reload,
    };
  },
  data() {
    return {
      isReload: true,
      types: "",
      dialogPercent: false,
      percent: 0,
    };
  },
  name: "app",
  components: {
    VLogin,
  },
  computed: {
    ...mapState(["levelName", "levelCode"]),
  },
  methods: {
    reload() {
      this.isReload = false;
      this.$nextTick(() => {
        this.isReload = true;
      });
    },
    //点击企业名称
    getEid(val, org) {
      let promise = new Promise((resolve, reject) => {
        // 获取companyId
        this.$get(this.$Url.company.getCompanyId, {
          keyword: val,
        }).then((res) => {
          let data = res.data;
          if (data && data.length > 0) {
            let eid = data[0] && data[0].eid;
            resolve(eid);
          } else {
            this.$message({
              type: "warning",
              message: "暂无数据",
            });
          }
        });
      });
      promise.then((eid) => {
        this.enterCompany(val, eid, true, org);
      });
    },
    enterCompany(companyName, eid, isNeedCheck, org) {
      localStorage.setItem("eid", eid);
      types = null;
      let checkUrl = this.$Url.search.check;
      if (!isNeedCheck) {
        checkUrl = this.$Url.search.check2;
      }
      let ths = this;
      this.$get(
        checkUrl,
        {
          companyName: companyName,
          eid: eid,
        },
        new axios.CancelToken(function executor(c) {
          ths.cancel = c;
        })
      ).then((res) => {
        const data = res.data;
        // 无访问权限
        if (res.status === 40305) {
          return;
        }

        // 默认重置公司是否有专利的cookie
        this.$cookie.set("isHavePatent", true);
        // 清除公司国别的cookie
        this.$cookie.remove("companyCountry");

        let promise = new Promise((resolve, reject) => {
          // 获取公司国别
          this.$get(this.$Url.company.country, {
            eid: eid,
          }).then((data) => {
            this.$cookie.set("companyCountry", data.data);
            resolve("next");
          });
        });
        promise.then(() => {
          if (data?.type == 0 || res.status === 40401) {
            this.addHistory(companyName, eid);
            // 获取新闻信息
            this.$post(this.$Url.news.getData, {
              name: companyName,
            }).then((data) => {});
            if (types != null) {
              clearTimeout(types);
              types = null;
            }
            this.$cookie.set("companyName", companyName);
            if (res.status === 40401) {
              this.$cookie.set("isHavePatent", false);
            }
            let val = {
              name: "technologyOverview",
            };
            this.dialogPercent = false;
            let url = this.$router.resolve(val);
            window.open(url.href, "_blank");
            // 企业的
          } else if (data.type == 1) {
            this.$confirm("后台生成数据需要一定的时间", "是否继续？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }).then(() => {
              // 获取新闻信息
              this.$post(this.$Url.news.getData, {
                name: companyName,
              }).then((data) => {

              });
              this.$get(this.$Url.search.generateData, {
                companyname: companyName,
                jueduidefen: true,
                eid: eid,
              }).then((res) => {
                if (res.status == 205) {
                  this.$message.warning(res.message);
                }
                this.addHistory(companyName, eid);
              });
            });
          } else if (data.type == 2) {
            this.dialogPercent = true;
            this.percent = Number(data.percent) || 0;
            types = setTimeout(() => {
              this.enterCompany(companyName, eid, false, org);
            }, 4000);
          } else if (data.type == 3) {
            this.closeTypes();
            this.$message.error("数据计算失败，请联系后台管理员！");
          }
        });
      });
    },
    closeTypes() {
      this.dialogPercent = false;
      clearTimeout(types);
      types = null;
      // 中止请求
      this.cancel();
      this.dialogPercent = false;
    },
    // 添加浏览历史
    addHistory(companyName, eid) {
      let obj = {
        companyName: companyName,
        eid: eid,
      };
      this.$post(this.$Url.history.addHistory, {
        sq: JSON.stringify(obj),
      }).then((res) => {});
    },
    // 判断设备是手机端还是pc端
    _isMobile() {
      // let is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null;
      // return is_mobi
      let flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      );
      return flag;
    },
    // 获取产业链全景图字典数据
    getDictAll() {
      this.$get(this.$Url.chain.dictAll).then((res) => {
        const data = res.data;
        localStorage.setItem("allDict", JSON.stringify(data));
      });
    },
  },
  created() {
    this.getDictAll();
  },
  mounted() {
    let that = this;
    this.$Bus.$on("progressBar", function(val) {
      // 针对桑基图
      if (val.eid) {
        if (val.type === "org") {
          that.enterCompany(val.name, val.eid, true, "org");
        } else {
          that.enterCompany(val.name, val.eid, true, "company");
        }
      } else {
        // 单一企业名字
        if (typeof val == "string") {
          that.getEid(val, "company");
        } else {
          that.getEid(val.name, "org");
        }
      }
    });
  },
};
</script>
<style lang="scss">
.el-message-box{
  .el-button--primary {
    color: #FFF;
    background-color: $mainColor !important;
    border-color: $mainColor !important;
}
.el-button--primary:active,.el-button--primary:focus,.el-button--primary:hover{
  color: #FFF !important;
    background-color: $mainColor !important;
    border-color: $mainColor !important;
}
.el-button:focus, .el-button:hover {
    color: $mainColor;
    border-color: $mainColor;
    background-color: $hoverColor;
}
}
</style>
<style lang="scss">
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

#app {
  height: 100%;
  // min-width: 1340px;
  font-family: "微软雅黑", Tahoma, Helvetica, Arial, sans-serif;
  // font-family: SourceHanSansCN-Regular, "微软雅黑", Tahoma, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // text-align: center;
  color: #2c3e50;
  /* margin-top: 60px; */
}

.container {
  padding: 0;
  max-width: 100% !important;
}
/* 引入行业版css */
/* 清除浮动 */
.clearfix:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
// 科技评价
.header-search-bar {
  .el-input__inner {
    border-color: #999 !important;
  }
}
.overview-info {
  .nav-menu {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  }
  .el-menu-item {
    color: #86899e;
    background-color: #fff;
    span {
      font-size: 14px;
      font-weight: bold;
    }
    &:hover,
    &:active {
      background-color: #eef1fa !important;
      span {
        color: #504da5;
      }
    }
  }
  .is-opened {
    .el-submenu__title {
      color: #504da5;
      background-color: #eef1fa !important;
      &:hover,
      &:active {
        background-color: #eef1fa !important;
      }
      .el-submenu__icon-arrow {
        font-weight: bold;
        color: #504da5 !important;
      }
    }
    .is-active {
      color: #fff !important;
      background-color: #bdc6de !important;
    }
  }
  .el-submenu__title {
    color: #86899e;
    background-color: #fff !important;
    &:hover,
    &:active {
      background-color: #eef1fa !important;
      span {
        color: #504da5;
      }
    }
  }
  .el-menu--inline {
    .el-menu-item {
      background-color: #eef1fa !important;
      &:hover,
      &:active {
        color: #fff !important;
        background-color: #bdc6de !important;
      }
      &.is-active {
        color: #fff !important;
        background-color: #bdc6de !important;
      }
    }
  }
  .el-submenu__icon-arrow {
    padding-top: 2px;
    font-size: 14px;
    color: #86899e !important;
  }

  // 专利评估
  .el-tabs__header {
    margin-bottom: 0;
  }
}
/* 产学研 */
.elrate {
  .el-icon-star-on {
    margin-right: 0 !important;
    font-size: 21px !important;
    color: #504da6 !important;
  }
  .el-icon-star-off {
    margin-right: 0 !important;
    font-size: 21px !important;
    color: #d1d6e3 !important;
    &:before {
      content: "\e797" !important;
    }
  }
}
.screen-box,
.main-box {
  .el-input__prefix {
    .el-input__icon {
      display: none;
    }
  }
  .el-input {
    border-radius: 4px;
  }
  .eldatepicker {
    .el-input__inner {
      padding-left: 10px !important;
    }
  }
  .el-input__inner {
    border: 0;
    border-radius: 4px;
    color: #86899e;
    background-color: #f3f5f8;
  }
  .el-input__suffix {
    margin-right: 4px;
    .el-input__icon {
      font-size: 14px;
      &:before {
        font-family: "element-icons" !important;
        color: #c0c4cc;
        content: "\e6df";
      }
    }
  }
}
::placeholder {
  color: #7674a3 !important;
}

// 产业链
.chain-box {
  .search-box {
    .el-input__suffix {
      i {
        padding-top: 4px !important;
        font-size: 20px;
      }
    }
  }
  .search-box2 {
    position: relative;
    width: 50%;
    margin-top: 10px;
    margin-left: 10px;
    .elinput .el-input__inner {
      height: 40px !important;
      padding-left: 15px !important;
    }
    .el-input-group__append {
      padding: 0 !important;
      border: 0;
      background-color: #524cab;
      outline: none;
      cursor: pointer;
      .el-icon-search {
        width: 58px;
        line-height: 40px;
        font-size: 17px;
        color: #fff !important;
      }
    }
  }
}

/* 提示框的样式 */
.g6-tooltip {
  border: 1px solid #e2e2e2;
  border-radius: 4px;
  font-size: 12px;
  color: #545454;
  background-color: rgba(255, 255, 255, 0.9);
  padding: 10px 8px;
  box-shadow: rgb(174, 174, 174) 0px 0px 10px;
}

// 专利质押融资
.query-inp {
  .el-input-group__append {
    width: 60px;
    border: 0;
    font-size: 18px;
    color: #fff;
    background-color: $mainColor;
    cursor: pointer;
    // .el-input__icon {
    //   display: inline-block;
    //   line-height: normal !important;
    //   padding: 0 16px;
    //   font-size: 18px;
    // }
  }
}

// 产学研搜索
.cxy-page {
  .el-input__prefix {
    left: 0 !important;
    .el-input__inner {
      padding-left: 30px !important;
    }
  }
  .el-input__inner {
    padding-left: 130px !important;
  }
}

// 产学研-人才检索
.synergy-talent {
  .search-time {
    .el-input__prefix {
      .el-icon-date {
        color: #c0c4cc !important;
      }
    }
  }
}

//
g {
  overflow: auto;
}

// 产业集群招商
.cluster-box {
  .search-box {
    .el-input__suffix {
      .el-input__clear {
        padding-top: 0 !important;
      }
    }
  }
}
</style>
